<!DOCTYPE html>
<!-- saved from url=(0073)http://mongodb.github.io/node-mongodb-native/3.1/quick-start/quick-start/ -->
<html lang="zh-CN" class="translated-ltr"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<meta name="keyword" content="">

    <link rel="shortcut icon" href="http://mongodb.github.io/node-mongodb-native/3.1/img/favicon.png">

    <title>快速开始</title>

    <link rel="stylesheet" href="./快速开始_files/bootstrap.css" type="text/css">
<link rel="stylesheet" href="./快速开始_files/font-awesome.min.css" type="text/css">
<link rel="stylesheet" href="./快速开始_files/mongodb-docs.css" type="text/css">
<link rel="stylesheet" href="./快速开始_files/overrides.css" type="text/css">
<link rel="stylesheet" href="./快速开始_files/idea.css">
<link rel="stylesheet" href="./快速开始_files/bootstrap-toggle.min.css" type="text/css">
<link rel="stylesheet" href="./快速开始_files/java.css" type="text/css">


  <link type="text/css" rel="stylesheet" charset="UTF-8" href="./快速开始_files/translateelement.css"></head>

  <body class="jsEnabled" style="">
  
  <section id="container" class="">
      
      <header id="header-db" class="row" role="navigation">
  <div class="header-content">
    <div class="toggle-nav pull-left">
        <i class="fa fa-bars"></i>
        <div class="icon-reorder tooltips" data-original-title="Toggle Navigation" data-placement="bottom"></div>
    </div>
    
    <div class="logo pull-left">
      <a href="https://www.mongodb.com/" target="_blank">
        <img src="./快速开始_files/logo-mongodb-header.png" ,="" alt="MongoDB.com">
      </a>
    </div>
    
    <div>
<div class="nav-items pull-right">
  <a href="https://university.mongodb.com/" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="Free Online Classes" target="_blank"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">MongoDB大学</font></font></a>
  <a href="http://www.mongodb.org/downloads" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="Download MongoDB" target="_blank"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">下载</font></font></a>
  <a href="http://www.mongodb.org/get-involved" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="Get involved with MongoDB" target="_blank"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">社区</font></font></a>
  <a href="http://docs.mongodb.org/" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="The MongoDB Documentation" target="_blank"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">文档</font></font></a>
  <a href="http://blog.mongodb.org/" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="The MongoDB Blog" target="_blank"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">博客</font></font></a>
  <div id="search">
<form method="get" action="http://www.google.com/search" target="_blank">
    <input type="text" name="searchQuery" size="20" value="" autocomplete="off" placeholder="Search docs">
    <input type="hidden" name="site" value="mongodb.github.io/node-mongodb-native/3.1">
    <input type="hidden" name="q" value="">
    <label for="searchQuery"><i class="fa fa-search fa-1"></i></label>
</form>
</div>

</div>
</div>

  </div>
</header>


      

      
<aside id="sidebar" class="sidebar">
    <div class="ssidebar nav-collapse">
      <div class="ssidebarwrapper">
        <h3>
          <a class="index-link" href="http://mongodb.github.io/node-mongodb-native/"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">MongoDB Node.js驱动程序</font></font></a>
          <a class="version pull-right" href="http://mongodb.github.io/node-mongodb-native/3.1"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">3.1</font></font></a>
        </h3>

        
        <ul class="sidebar-menu">
          
          
          
          
          
          
          
          
          
          
          
          

          
          
            
            









  


          
            
            









  
  
  
  
  
  
  
  

  


          
            
            









  
    
    
      
      
    
      
      
    
      
      
    
      
      
    
      
      
    
      
      
    
      
      
    
      
      
    
      
      
    
      
      
    
      
      
    
    
  


          
            
            









  
    
    
      
      
    
      
      
    
      
      
    
      
      
    
      
      
    
    
  


          
            
            









  
    
    
      
      
    
    
  


          
            
            









  


          
            
            









  


          
            
            









  


          
            
            









  


          

          

          
            
            
















    <li class="toctree-l1">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/installation-guide/installation-guide/">
        <i class="fa fa-puzzle-piece"></i><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">
        安装指南
    </font></font></a>
  </li>


          
            
            













  




    <li class="toctree-l1">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/quick-start/quick-start/">
        <i class="fa fa-road"></i><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">
        快速开始
    </font></font></a>
  </li>


          
            
            
















<li class="toctree-l1 ">
  <a href="http://mongodb.github.io/node-mongodb-native/3.1/tutorials/main/" class="">
      <i class="fa fa-thumb-tack"></i>
      <span><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">教程</font></font></span>
      <span class="menu-arrow fa fa-angle-right"></span>
  </a>
    <ul>
        
        
        
        
















<li class="toctree-l2 ">
  <a href="http://mongodb.github.io/node-mongodb-native/3.1/tutorials/connect/" class="">
      <i class="fa"></i>
      <span><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">连接到MongoDB</font></font></span>
      
  </a>
    <ul>
        
        
        
        
















    <li class="toctree-l3">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/tutorials/connect/authenticating/">
        <i class="fa"></i><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">
        认证
    </font></font></a>
  </li>


        
        
        
        
        
















    <li class="toctree-l3">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/tutorials/connect/ssl/">
        <i class="fa"></i><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">
        SSL设置
    </font></font></a>
  </li>


        
        
    </ul>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/tutorials/collations/">
        <i class="fa"></i><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">
        排序规则
    </font></font></a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/tutorials/collections/">
        <i class="fa"></i><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">
        集合
    </font></font></a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/tutorials/create-indexes/">
        <i class="fa"></i><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">
        创建索引
    </font></font></a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/tutorials/crud/">
        <i class="fa"></i><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">
        CRUD操作
    </font></font></a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/tutorials/projections/">
        <i class="fa"></i><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">
        预测
    </font></font></a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/tutorials/aggregation/">
        <i class="fa"></i><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">
        聚合
    </font></font></a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/tutorials/text-search/">
        <i class="fa"></i><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">
        文字搜索
    </font></font></a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/tutorials/geospatial-search/">
        <i class="fa"></i>
        Geospatial Search
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/tutorials/commands/">
        <i class="fa"></i>
        Database Commands
    </a>
  </li>


        
        
        
        
        
















<li class="toctree-l2 ">
  <a href="http://mongodb.github.io/node-mongodb-native/3.1/tutorials/gridfs/" class="">
      <i class="fa"></i>
      <span>GridFS</span>
      
  </a>
    <ul>
        
        
        
        
















    <li class="toctree-l3">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/tutorials/gridfs/streaming/">
        <i class="fa"></i>
        GridFS API
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l3">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/tutorials/gridfs/gridstore/">
        <i class="fa"></i>
        Legacy GridStore
    </a>
  </li>


        
        
    </ul>
  </li>


        
        
    </ul>
  </li>


          
            
            
















<li class="toctree-l1 ">
  <a href="http://mongodb.github.io/node-mongodb-native/3.1/reference/main/" class="">
      <i class="fa fa-book"></i>
      <span><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">参考</font></font></span>
      <span class="menu-arrow fa fa-angle-right"></span>
  </a>
    <ul>
        
        
        
        
















<li class="toctree-l2 ">
  <a href="http://mongodb.github.io/node-mongodb-native/3.1/reference/connecting/" class="">
      <i class="fa"></i>
      <span>Connection Options</span>
      
  </a>
    <ul>
        
        
        
        
















    <li class="toctree-l3">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/reference/connecting/connection-settings/">
        <i class="fa"></i>
        Connection Settings
    </a>
  </li>


        
        
    </ul>
  </li>


        
        
        
        
        
















<li class="toctree-l2 ">
  <a href="http://mongodb.github.io/node-mongodb-native/3.1/reference/ecmascriptnext/" class="">
      <i class="fa"></i>
      <span>ECMAScript Next</span>
      
  </a>
    <ul>
        
        
        
        
















    <li class="toctree-l3">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/reference/ecmascriptnext/connecting/">
        <i class="fa"></i>
        Connecting
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l3">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/reference/ecmascriptnext/crud/">
        <i class="fa"></i>
        CRUD Operations
    </a>
  </li>


        
        
    </ul>
  </li>


        
        
        
        
        
















<li class="toctree-l2 ">
  <a href="http://mongodb.github.io/node-mongodb-native/3.1/reference/management/" class="">
      <i class="fa"></i>
      <span>Management</span>
      
  </a>
    <ul>
        
        
        
        
















    <li class="toctree-l3">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/reference/management/logging/">
        <i class="fa"></i>
        Logging
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l3">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/reference/management/apm/">
        <i class="fa"></i>
        APM
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l3">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/reference/management/sdam-monitoring/">
        <i class="fa"></i>
        Topology Monitoring
    </a>
  </li>


        
        
    </ul>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/reference/pool/">
        <i class="fa"></i>
        Pool Design
    </a>
  </li>


        
        
        
        
        
















    <li class="toctree-l2">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/reference/faq/">
        <i class="fa"></i>
        Frequently Asked Questions
    </a>
  </li>


        
        
    </ul>
  </li>


          
            
            
















<li class="toctree-l1 ">
  <a href="http://mongodb.github.io/node-mongodb-native/3.1/upgrade-migration/main/" class="">
      <i class="fa fa-cog"></i>
      <span><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">升级指南</font></font></span>
      <span class="menu-arrow fa fa-angle-right"></span>
  </a>
    <ul>
        
        
        
        
















    <li class="toctree-l2">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/upgrade-migration/upgrading/">
        <i class="fa fa-wrench"></i>
        Upgrading to 2.x
    </a>
  </li>


        
        
    </ul>
  </li>


          
            
            
















    <li class="toctree-l1">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/api">
        <i class="fa fa-file-text-o"></i><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">
        API文档
    </font></font></a>
  </li>


          
            
            
















    <li class="toctree-l1">
    <a href="https://github.com/mongodb/node-mongodb-native" target="_blank">
        <i class="fa fa-github"></i><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">
        源代码
    </font></font></a>
  </li>


          
            
            
















    <li class="toctree-l1">
    <a href="http://mongodb.github.io/node-mongodb-native/3.1/issues-help/">
        <i class="fa fa-life-ring"></i><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">
        问题与帮助
    </font></font></a>
  </li>


          
            
            
















    <li class="toctree-l1">
    <a href="https://gitter.im/mongodb/node-mongodb-native?utm_source=badge&amp;utm_medium=badge&amp;utm_campaign=pr-badge" target="_blank">
        <img src="./快速开始_files/Join Chat.svg">
        
    </a>
  </li>


          
        </ul>
        
    </div>
  </div>
  
</aside>

<div class="option-popup closed" id="optionsVersionsPopup">
<div class="option-header">
  <i class="fa fa-gear"></i>
  <span><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">OPTIONS</font></font></span>
  <i class="fa fa-angle-up pull-right"></i>
</div>
<div class="option-body">
  <ul>
      
      <li>
        <label><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">版</font></font></label>
        <div class="btn-group btn-group-xs pull-right">
          <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">
            选择版本 </font></font><span class="caret"></span>
          </button>
          <ul class="dropdown-menu" role="menu" id="optionsVersionsMenu">
          <li><a href="http://mongodb.github.io/node-mongodb-native/3.2" data-path="manual">3.2</a></li><li class="active"><a href="http://mongodb.github.io/node-mongodb-native/3.1" data-path="manual">3.1</a></li><li><a href="http://mongodb.github.io/node-mongodb-native/3.0" data-path="manual">3.0</a></li><li><a href="http://mongodb.github.io/node-mongodb-native/2.2" data-path="manual">2.2</a></li><li><a href="http://mongodb.github.io/node-mongodb-native/core" data-path="manual">core</a></li></ul>
        </div>
      </li>

   


    

  </ul>
</div>
</div>



      
      <section id="main-content" class="content">
          <section class="main-column pull-left">
            <div class="document">
              <div class="documentwrapper">
                <div class="bodywrapper">
                  <div class="body">
                    <p></p><div class="admonition note">
                    <h5 class="admonition-title"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">调查</font></font></h5>
                    <p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">请在我们的</font></font><a href="https://www.research.net/r/BPJSGJC" target="_blank"><strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">用户调查中</font></font></strong></a><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">回答几个问题，帮助我们改进
						 </font><font style="vertical-align: inherit;">。
                    </font></font></p>
                    </div>
                    <p></p>


   
<a class="edit-link" href="https://github.com/mongodb/node-mongodb-native/blob/3.1/docs/reference/content/quick-start/quick-start.md" target="_blank" title="在GitHub上编辑quick-start / quick-start.md"><i class="fa fa-pencil-square-o"></i></a>










<div class="bc">
<ul>
  
  
  
  
  
  
  <li><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">快速开始</font></font></li>
</ul>
</div>




<h1 id="quick-start"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">快速开始</font></font></h1>

<p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">本指南将向您展示如何使用Node.js和MongoDB设置一个简单的应用程序。</font><font style="vertical-align: inherit;">它的范围只是如何设置驱动程序和执行简单的CRUD操作。</font><font style="vertical-align: inherit;">有关更深入的报道，请参阅</font></font><a href="http://mongodb.github.io/node-mongodb-native/3.1/reference/main/"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">教程</font></font></a><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">。</font></font></p>

<h2 id="create-the-package-json-file"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">创建package.json文件</font></font></h2>

<p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">首先，创建一个应用程序所在的目录。</font></font></p>

<pre><code class="hljs bash">mkdir myproject
<span class="hljs-built_in">cd</span> myproject
</code></pre>

<p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">输入以下命令并回答问题以创建新项目的初始结构：</font></font></p>

<pre><code class="hljs coffeescript"><span class="hljs-built_in">npm</span> init
</code></pre>

<p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">接下来，安装驱动程序依赖项。</font></font></p>

<pre><code class="hljs coffeescript"><span class="hljs-built_in">npm</span> install mongodb --save
</code></pre>

<p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">你应该看到</font></font><strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">NPM</font></font></strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">下载了很多文件。</font><font style="vertical-align: inherit;">完成后，您将在</font></font><strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">node_modules</font></font></strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">目录</font><font style="vertical-align: inherit;">下找到所有下载的软件包</font><font style="vertical-align: inherit;">。</font></font></p>

<h2 id="start-a-mongodb-server"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">启动MongoDB服务器</font></font></h2>

<p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">有关完整的MongoDB安装说明，请参阅</font></font><a href="https://docs.mongodb.org/manual/installation/" target="_blank"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">手册</font></font></a><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">。</font></font></p>

<ol>
<li><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">从</font><a href="https://www.mongodb.org/downloads" target="_blank"><font style="vertical-align: inherit;">MongoDB</font></a><font style="vertical-align: inherit;">下载正确的MongoDB版本</font></font><a href="https://www.mongodb.org/downloads" target="_blank"><font style="vertical-align: inherit;"></font></a></li>
<li><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">创建一个数据库目录（在本例中为</font></font><strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">/ data</font></font></strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">）。</font></font></li>
<li><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">安装并启动一个</font></font><code>mongod</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">过程。</font></font></li>
</ol>

<pre><code class="hljs">mongod --dbpath=/data
</code></pre>

<p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">您应该看到</font></font><strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">mongod</font></font></strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">进程启动并打印一些状态信息。</font></font></p>

<h2 id="connect-to-mongodb"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">连接到MongoDB</font></font></h2>

<p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">创建一个新的</font></font><strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">app.js</font></font></strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">文件并添加以下代码以使用MongoDB驱动程序尝试一些基本的CRUD操作。</font></font></p>

<p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">添加代码以连接到服务器和数据库</font></font><strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">myproject</font></font></strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">：</font></font></p>

<pre><code class="language-js hljs javascript"><span class="hljs-keyword">const</span> MongoClient = <span class="hljs-built_in">require</span>(<span class="hljs-string">'mongodb'</span>).MongoClient;
<span class="hljs-keyword">const</span> assert = <span class="hljs-built_in">require</span>(<span class="hljs-string">'assert'</span>);<font></font>
<font></font>
<span class="hljs-comment">// Connection URL</span>
<span class="hljs-keyword">const</span> url = <span class="hljs-string">'mongodb://localhost:27017'</span>;<font></font>
<font></font>
<span class="hljs-comment">// Database Name</span>
<span class="hljs-keyword">const</span> dbName = <span class="hljs-string">'myproject'</span>;<font></font>
<font></font>
<span class="hljs-comment">// Create a new MongoClient</span>
<span class="hljs-keyword">const</span> client = <span class="hljs-keyword">new</span> MongoClient(url);<font></font>
<font></font>
<span class="hljs-comment">// Use connect method to connect to the Server</span>
client.connect(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(err)</span> </span>{<font></font>
  assert.equal(<span class="hljs-literal">null</span>, err);
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Connected successfully to server"</span>);<font></font>
<font></font>
  <span class="hljs-keyword">const</span> db = client.db(dbName);<font></font>
<font></font>
  client.close();<font></font>
});<font></font>
<font></font>
</code></pre>

<p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">从命令行运行您的应用程序：</font></font></p>

<pre><code class="hljs">node app.js
</code></pre>

<p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">应用程序应</font></font><strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">成功将已连接</font></font></strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">打印</font><strong><font style="vertical-align: inherit;">到服务器</font></strong><font style="vertical-align: inherit;">到控制台。</font></font></p>

<h2 id="insert-a-document"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">插入文档</font></font></h2>

<p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">向</font></font><strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">app.js</font></font></strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">添加</font><font style="vertical-align: inherit;">以下函数，该函数使用</font></font><strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">insertMany</font></font></strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;"> 
方法将三个文档添加到</font></font><strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">文档</font></font></strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">集合中。</font></font></p>

<pre><code class="language-js hljs javascript"><span class="hljs-keyword">const</span> insertDocuments = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(db, callback)</span> </span>{
  <span class="hljs-comment">// Get the documents collection</span>
  <span class="hljs-keyword">const</span> collection = db.collection(<span class="hljs-string">'documents'</span>);
  <span class="hljs-comment">// Insert some documents</span><font></font>
  collection.insertMany([<font></font>
    {a : <span class="hljs-number">1</span>}, {a : <span class="hljs-number">2</span>}, {a : <span class="hljs-number">3</span>}<font></font>
  ], <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(err, result)</span> </span>{<font></font>
    assert.equal(err, <span class="hljs-literal">null</span>);<font></font>
    assert.equal(<span class="hljs-number">3</span>, result.result.n);<font></font>
    assert.equal(<span class="hljs-number">3</span>, result.ops.length);
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Inserted 3 documents into the collection"</span>);<font></font>
    callback(result);<font></font>
  });<font></font>
}<font></font>
</code></pre>

<p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">所述</font></font><strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">插入件</font></font></strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">命令返回具有以下字段的对象：</font></font></p>

<ul>
<li><strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">result</font></font></strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">包含MongoDB的结果文档</font></font></li>
<li><strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">ops</font></font></strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">包含使用添加的</font></font><strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">_id</font></font></strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">字段</font><font style="vertical-align: inherit;">插入的文档</font></font></li>
<li><strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">connection</font></font></strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">包含用于执行插入的连接</font></font></li>
</ul>

<p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">添加以下代码以调用</font></font><strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">insertDocuments</font></font></strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">函数：</font></font></p>

<pre><code class="language-js hljs javascript"><span class="hljs-keyword">const</span> MongoClient = <span class="hljs-built_in">require</span>(<span class="hljs-string">'mongodb'</span>).MongoClient;
<span class="hljs-keyword">const</span> assert = <span class="hljs-built_in">require</span>(<span class="hljs-string">'assert'</span>);<font></font>
<font></font>
<span class="hljs-comment">// Connection URL</span>
<span class="hljs-keyword">const</span> url = <span class="hljs-string">'mongodb://localhost:27017'</span>;<font></font>
<font></font>
<span class="hljs-comment">// Database Name</span>
<span class="hljs-keyword">const</span> dbName = <span class="hljs-string">'myproject'</span>;
<span class="hljs-keyword">const</span> client = <span class="hljs-keyword">new</span> MongoClient(url, { useNewUrlParser: <span class="hljs-literal">true</span> });<font></font>
<font></font>
<span class="hljs-comment">// Use connect method to connect to the server</span>
client.connect(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(err)</span> </span>{<font></font>
  assert.equal(<span class="hljs-literal">null</span>, err);
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Connected successfully to server"</span>);<font></font>
<font></font>
  <span class="hljs-keyword">const</span> db = client.db(dbName);<font></font>
<font></font>
  insertDocuments(db, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{<font></font>
    client.close();<font></font>
  });<font></font>
});<font></font>
</code></pre>

<p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">运行更新的</font></font><strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">app.js</font></font></strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">文件：</font></font></p>

<pre><code class="hljs">node app.js
</code></pre>

<p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">该操作返回以下输出：</font></font></p>

<pre><code class="hljs cs">Connected successfully to server<font></font>
Inserted <span class="hljs-number">3</span> documents <span class="hljs-keyword">into</span> the collection
</code></pre>

<h2 id="find-all-documents"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">查找所有文档</font></font></h2>

<p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">添加一个返回所有文档的查询。</font></font></p>

<pre><code class="language-js hljs javascript"><span class="hljs-keyword">const</span> findDocuments = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(db, callback)</span> </span>{
  <span class="hljs-comment">// Get the documents collection</span>
  <span class="hljs-keyword">const</span> collection = db.collection(<span class="hljs-string">'documents'</span>);
  <span class="hljs-comment">// Find some documents</span>
  collection.find({}).toArray(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(err, docs)</span> </span>{<font></font>
    assert.equal(err, <span class="hljs-literal">null</span>);
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Found the following records"</span>);
    <span class="hljs-built_in">console</span>.log(docs)<font></font>
    callback(docs);<font></font>
  });<font></font>
}<font></font>
</code></pre>

<!---
Changed console.dir to console.log, since most users will be running these examples from the command line
rather than from within a browser console, and console.log returns better formatting.
-->

<p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">此查询返回</font></font><strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">文档</font></font></strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">集合</font><font style="vertical-align: inherit;">中的所有</font><strong><font style="vertical-align: inherit;">文档</font></strong><font style="vertical-align: inherit;">。</font><font style="vertical-align: inherit;">将</font></font><strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">findDocument</font></font></strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">方法</font><font style="vertical-align: inherit;">添加</font><font style="vertical-align: inherit;">到</font></font><strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">client.connect</font></font></strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">回调：</font></font></p>

<!---
Removed the assert line for number of documents returned on the grounds that it's too brittle.
It's better if these code examples are idempotent, and if this one
is run repeatedly the number of documents in the collection will change.
-->

<pre><code class="language-js hljs javascript"><span class="hljs-keyword">const</span> MongoClient = <span class="hljs-built_in">require</span>(<span class="hljs-string">'mongodb'</span>).MongoClient;
<span class="hljs-keyword">const</span> assert = <span class="hljs-built_in">require</span>(<span class="hljs-string">'assert'</span>);<font></font>
<font></font>
<span class="hljs-comment">// Connection URL</span>
<span class="hljs-keyword">const</span> url = <span class="hljs-string">'mongodb://localhost:27017'</span>;<font></font>
<font></font>
<span class="hljs-comment">// Database Name</span>
<span class="hljs-keyword">const</span> dbName = <span class="hljs-string">'myproject'</span>;<font></font>
<font></font>
<span class="hljs-keyword">const</span> client = <span class="hljs-keyword">new</span> MongoClient(url);
<span class="hljs-comment">// Use connect method to connect to the server</span>
client.connect(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(err)</span> </span>{<font></font>
  assert.equal(<span class="hljs-literal">null</span>, err);
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Connected correctly to server"</span>);<font></font>
<font></font>
  <span class="hljs-keyword">const</span> db = client.db(dbName);<font></font>
<font></font>
  insertDocuments(db, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{<font></font>
    findDocuments(db, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{<font></font>
      client.close();<font></font>
    });<font></font>
  });<font></font>
});<font></font>
</code></pre>

<h2 id="find-documents-with-a-query-filter"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">使用查询过滤器查找文档</font></font></h2>

<p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">添加查询过滤器以仅查找符合查询条件的文档。</font></font></p>

<pre><code class="language-js hljs javascript"><span class="hljs-keyword">const</span> findDocuments = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(db, callback)</span> </span>{
  <span class="hljs-comment">// Get the documents collection</span>
  <span class="hljs-keyword">const</span> collection = db.collection(<span class="hljs-string">'documents'</span>);
  <span class="hljs-comment">// Find some documents</span>
  collection.find({<span class="hljs-string">'a'</span>: <span class="hljs-number">3</span>}).toArray(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(err, docs)</span> </span>{<font></font>
    assert.equal(err, <span class="hljs-literal">null</span>);
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Found the following records"</span>);
    <span class="hljs-built_in">console</span>.log(docs);<font></font>
    callback(docs);<font></font>
  });<font></font>
}<font></font>
</code></pre>

<p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">只</font></font><code>'a' : 3</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">应返回</font><font style="vertical-align: inherit;">匹配的文档</font><font style="vertical-align: inherit;">。</font></font></p>

<h2 id="update-a-document"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">更新文档</font></font></h2>

<p>The following operation updates a document in the <strong>documents</strong> collection.</p>

<pre><code class="language-js hljs javascript"><span class="hljs-keyword">const</span> updateDocument = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(db, callback)</span> </span>{
  <span class="hljs-comment">// Get the documents collection</span>
  <span class="hljs-keyword">const</span> collection = db.collection(<span class="hljs-string">'documents'</span>);
  <span class="hljs-comment">// Update document where a is 2, set b equal to 1</span>
  collection.updateOne({ a : <span class="hljs-number">2</span> }<font></font>
    , { $set: { b : <span class="hljs-number">1</span> } }, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(err, result)</span> </span>{<font></font>
    assert.equal(err, <span class="hljs-literal">null</span>);<font></font>
    assert.equal(<span class="hljs-number">1</span>, result.result.n);
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Updated the document with the field a equal to 2"</span>);<font></font>
    callback(result);<font></font>
  });  <font></font>
}<font></font>
</code></pre>

<p>The method updates the first document where the field <strong>a</strong> is equal to <strong>2</strong> by adding a new field <strong>b</strong> to the document set to <strong>1</strong>. Next, update the callback function from <strong>client.connect</strong> to include the update method.</p>

<pre><code class="language-js hljs javascript"><span class="hljs-keyword">const</span> MongoClient = <span class="hljs-built_in">require</span>(<span class="hljs-string">'mongodb'</span>).MongoClient;
<span class="hljs-keyword">const</span> assert = <span class="hljs-built_in">require</span>(<span class="hljs-string">'assert'</span>);<font></font>
<font></font>
<span class="hljs-comment">// Connection URL</span>
<span class="hljs-keyword">const</span> url = <span class="hljs-string">'mongodb://localhost:27017'</span>;<font></font>
<font></font>
<span class="hljs-comment">// Database Name</span>
<span class="hljs-keyword">const</span> dbName = <span class="hljs-string">'myproject'</span>;<font></font>
<font></font>
<span class="hljs-keyword">const</span> client = <span class="hljs-keyword">new</span> MongoClient(url);
<span class="hljs-comment">// Use connect method to connect to the server</span>
client.connect(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(err)</span> </span>{<font></font>
  assert.equal(<span class="hljs-literal">null</span>, err);
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Connected successfully to server"</span>);<font></font>
<font></font>
  <span class="hljs-keyword">const</span> db = client.db(dbName);<font></font>
<font></font>
  insertDocuments(db, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{<font></font>
    updateDocument(db, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{<font></font>
      client.close();<font></font>
    });<font></font>
  });<font></font>
});<font></font>
</code></pre>

<h2 id="remove-a-document">Remove a document</h2>

<p>Remove the document where the field <strong>a</strong> is equal to <strong>3</strong>.</p>

<pre><code class="language-js hljs javascript"><span class="hljs-keyword">const</span> removeDocument = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(db, callback)</span> </span>{
  <span class="hljs-comment">// Get the documents collection</span>
  <span class="hljs-keyword">const</span> collection = db.collection(<span class="hljs-string">'documents'</span>);
  <span class="hljs-comment">// Delete document where a is 3</span>
  collection.deleteOne({ a : <span class="hljs-number">3</span> }, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(err, result)</span> </span>{<font></font>
    assert.equal(err, <span class="hljs-literal">null</span>);<font></font>
    assert.equal(<span class="hljs-number">1</span>, result.result.n);
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Removed the document with the field a equal to 3"</span>);<font></font>
    callback(result);<font></font>
  });    <font></font>
}<font></font>
</code></pre>

<p>Add the new method to the <strong>client.connect</strong> callback function.</p>

<pre><code class="language-js hljs javascript"><span class="hljs-keyword">const</span> MongoClient = <span class="hljs-built_in">require</span>(<span class="hljs-string">'mongodb'</span>).MongoClient;
<span class="hljs-keyword">const</span> assert = <span class="hljs-built_in">require</span>(<span class="hljs-string">'assert'</span>);<font></font>
<font></font>
<span class="hljs-comment">// Connection URL</span>
<span class="hljs-keyword">const</span> url = <span class="hljs-string">'mongodb://localhost:27017'</span>;<font></font>
<font></font>
<span class="hljs-comment">// Database Name</span>
<span class="hljs-keyword">const</span> dbName = <span class="hljs-string">'myproject'</span>;<font></font>
<font></font>
<span class="hljs-keyword">const</span> client = <span class="hljs-keyword">new</span> MongoClient(url);
<span class="hljs-comment">// Use connect method to connect to the server</span>
client.connect(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(err)</span> </span>{<font></font>
  assert.equal(<span class="hljs-literal">null</span>, err);
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Connected successfully to server"</span>);<font></font>
<font></font>
  <span class="hljs-keyword">const</span> db = client.db(dbName);<font></font>
<font></font>
  insertDocuments(db, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{<font></font>
    updateDocument(db, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{<font></font>
      removeDocument(db, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{<font></font>
        client.close();<font></font>
      });<font></font>
    });<font></font>
  });<font></font>
});<font></font>
</code></pre>

<h2 id="index-a-collection">Index a Collection</h2>

<p><a href="https://docs.mongodb.org/manual/indexes/" target="_blank"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">索引</font></font></a><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">可以提高应用程序的性能。</font><font style="vertical-align: inherit;">以下函数</font><font style="vertical-align: inherit;">在</font><strong><font style="vertical-align: inherit;">文档</font></strong><font style="vertical-align: inherit;">集合中</font></font><strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">的</font></font></strong><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">字段
 </font><font style="vertical-align: inherit;">上创建索引</font><font style="vertical-align: inherit;">。</font></font><strong><font style="vertical-align: inherit;"></font></strong><font style="vertical-align: inherit;"></font></p>

<pre><code class="language-js hljs javascript"><span class="hljs-keyword">const</span> indexCollection = <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(db, callback)</span> </span>{<font></font>
  db.collection(<span class="hljs-string">'documents'</span>).createIndex(<font></font>
    { <span class="hljs-string">"a"</span>: <span class="hljs-number">1</span> },
      <span class="hljs-literal">null</span>,
      <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(err, results)</span> </span>{
        <span class="hljs-built_in">console</span>.log(results);<font></font>
        callback();<font></font>
    }<font></font>
  );<font></font>
};<font></font>
</code></pre>

<p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">将</font></font><code>indexCollection</code><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">方法</font><font style="vertical-align: inherit;">添加</font><font style="vertical-align: inherit;">到您的应用：</font></font></p>

<pre><code class="language-js hljs javascript"><span class="hljs-keyword">const</span> MongoClient = <span class="hljs-built_in">require</span>(<span class="hljs-string">'mongodb'</span>).MongoClient;
<span class="hljs-keyword">const</span> assert = <span class="hljs-built_in">require</span>(<span class="hljs-string">'assert'</span>);<font></font>
<font></font>
<span class="hljs-comment">// Connection URL</span>
<span class="hljs-keyword">const</span> url = <span class="hljs-string">'mongodb://localhost:27017'</span>;<font></font>
<font></font>
<span class="hljs-keyword">const</span> dbName = <span class="hljs-string">'myproject'</span>;<font></font>
<font></font>
<span class="hljs-keyword">const</span> client = <span class="hljs-keyword">new</span> MongoClient(url);
<span class="hljs-comment">// Use connect method to connect to the server</span>
client.connect(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(err)</span> </span>{<font></font>
  assert.equal(<span class="hljs-literal">null</span>, err);
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Connected successfully to server"</span>);<font></font>
<font></font>
  <span class="hljs-keyword">const</span> db = client.db(dbName);<font></font>
<font></font>
  insertDocuments(db, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{<font></font>
    indexCollection(db, <span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">()</span> </span>{<font></font>
      client.close();<font></font>
    });<font></font>
  });<font></font>
});<font></font>
</code></pre>

<p><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">有关更多详细信息，请参阅</font></font><a href="http://mongodb.github.io/node-mongodb-native/3.1/tutorials/main/"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">教程</font></font></a><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">。</font></font></p>






<div id="btnv">
  
  
</div>
</div>


</div>
<div class="right-column">
<div class="wrapper">
  
  <div class="toc" style="display: block;">
    <span class="toc-header"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">在本页面</font></font></span>
    <nav id="TableOfContents">
<ul>
<li><a href="http://mongodb.github.io/node-mongodb-native/3.1/quick-start/quick-start/#quick-start"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">快速开始</font></font></a>
<ul>
<li><a href="http://mongodb.github.io/node-mongodb-native/3.1/quick-start/quick-start/#create-the-package-json-file"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">创建package.json文件</font></font></a></li>
<li><a href="http://mongodb.github.io/node-mongodb-native/3.1/quick-start/quick-start/#start-a-mongodb-server"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">启动MongoDB服务器</font></font></a></li>
<li><a href="http://mongodb.github.io/node-mongodb-native/3.1/quick-start/quick-start/#connect-to-mongodb"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">连接到MongoDB</font></font></a></li>
<li><a href="http://mongodb.github.io/node-mongodb-native/3.1/quick-start/quick-start/#insert-a-document"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">插入文档</font></font></a></li>
<li><a href="http://mongodb.github.io/node-mongodb-native/3.1/quick-start/quick-start/#find-all-documents"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">查找所有文档</font></font></a></li>
<li><a href="http://mongodb.github.io/node-mongodb-native/3.1/quick-start/quick-start/#find-documents-with-a-query-filter"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">使用查询过滤器查找文档</font></font></a></li>
<li><a href="http://mongodb.github.io/node-mongodb-native/3.1/quick-start/quick-start/#update-a-document"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">更新文档</font></font></a></li>
<li><a href="http://mongodb.github.io/node-mongodb-native/3.1/quick-start/quick-start/#remove-a-document"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">删除文档</font></font></a></li>
<li><a href="http://mongodb.github.io/node-mongodb-native/3.1/quick-start/quick-start/#index-a-collection"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">索引集合</font></font></a></li>
</ul></li>
</ul>
</nav>
  </div>
  
</div>
</div>

</div>
</div>

</section>
</section>

</section>


<script async="" src="./快速开始_files/analytics.js.下载"></script><script type="text/javascript">
  var DOCUMENTATION_OPTIONS = {
   URL_ROOT:    "/node-mongodb-native/3.1",
   VERSION:     "3.1",
   COLLAPSE_INDEX: false,
   FILE_SUFFIX: '.html',
   HAS_SOURCE:  true
  };
</script>
<script type="text/javascript" src="./快速开始_files/jquery.js.下载"></script>
<script type="text/javascript" src="./快速开始_files/bootstrap.js.下载"></script>
<script type="text/javascript" src="./快速开始_files/navbar.js.下载"></script>
<script type="text/javascript" src="./快速开始_files/highlight.pack.js.下载"></script>
<script type="text/javascript" src="./快速开始_files/scripts.js.下载"></script>
<script type="text/javascript" src="./快速开始_files/bootstrap-toggle.min.js.下载"></script>
<script type="text/javascript" src="./快速开始_files/java.js.下载"></script>
<script type="text/javascript" src="./快速开始_files/toggle-switch.js.下载"></script>

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-29229787-1', 'auto');
  ga('send', 'pageview');
</script><div id="goog-gt-tt" class="skiptranslate" dir="ltr"><div style="padding: 8px;"><div><div class="logo"><img src="./快速开始_files/translate_24dp.png" width="20" height="20" alt="Google 翻译"></div></div></div><div class="top" style="padding: 8px; float: left; width: 100%;"><h1 class="title gray">原文</h1></div><div class="middle" style="padding: 8px;"><div class="original-text"></div></div><div class="bottom" style="padding: 8px;"><div class="activity-links"><span class="activity-link">提供更好的翻译建议</span><span class="activity-link"></span></div><div class="started-activity-container"><hr style="color: #CCC; background-color: #CCC; height: 1px; border: none;"><div class="activity-root"></div></div></div><div class="status-message" style="display: none;"></div></div>



<div class="goog-te-spinner-pos"><div class="goog-te-spinner-animation"><svg xmlns="http://www.w3.org/2000/svg" class="goog-te-spinner" width="96px" height="96px" viewBox="0 0 66 66"><circle class="goog-te-spinner-path" fill="none" stroke-width="6" stroke-linecap="round" cx="33" cy="33" r="30"></circle></svg></div></div></body></html>